package com.lupan.classicsJava.jpa.dao;

import com.lupan.classicsJava.jpa.domain.BaseEntity;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.Date;

/**
 * 说明：
 *
 * @author lupan
 * @version 2017/3/8 15:48
 */
public abstract class BaseJpaDao {

    @PersistenceContext
    private EntityManager em;

    @Transactional
    public <T extends BaseEntity> T save(T t){
        Date date = new Date();
        t.setCreatedTime(date);
        t.setUpdatedTime(date);
        return em.merge(t);
    }
}
